package com.javasoft.controller.XGX;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javasoft.entity.XGX.Question;
import com.javasoft.service.XGX.impl.QuestionImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/questions")
public class QuestionController {
    /**
     * 创建 question业务逻辑实现实体
     */
    @Autowired
    private QuestionImpl question_impl;

    /**
     * 前端可输入多个查询条件查询题库
     * @param id
     * @param des
     * @param currentPage
     * @param pageSize
     * @param knoPoint
     * @param type
     * @param subject
     * @param difRank
     * @return
     */
    @GetMapping("/search")
    public Page<Question> searchPage(
            @RequestParam(value = "id",required = false) Long id,//id不是必须的,可以设置成required = false
            @RequestParam(value = "des",required = false) String des,
            @RequestParam(defaultValue = "1",value = "currentPage") Integer currentPage,
            @RequestParam(defaultValue = "15",value = "pageSize") Integer pageSize,
            @RequestParam(value = "knoPoint",required = false) String knoPoint,
            @RequestParam(value = "type",required = false) String type,
            @RequestParam(value = "subject",required = false) String subject,
            @RequestParam(defaultValue = "-1",value = "difRank",required = false) Integer difRank


    ){
        return question_impl.searchPage(
                id,
                currentPage,
                pageSize,
                des,
                knoPoint,
                type,
                subject,
                difRank);
    }

    /**
     * 更新或保存新的题目
     * @param newQuestions
     * @return id
     */
    @PostMapping("/save")
    public Long saveOrUpdate(@RequestBody Question newQuestions){
        return question_impl.saveOrupdate(newQuestions);//这个是impl里面定义的
    }

    /**
     * 根据输入的题目id删除题目
     * @param ids
     * @return deleted_ids
     */

    @PostMapping("/delete")
    public List<Integer> delete(@RequestBody List<Integer> ids){
        return question_impl.deleteBatchIds(ids);
    }

    /**
     * 获取全部题目
     * @return all_pages
     */
    @GetMapping("/all")
    public Page<Question> getAllData(@RequestParam(defaultValue = "1",value = "currentPage") Integer currentPage,
                                     @RequestParam(defaultValue = "15",value = "pageSize") Integer pageSize) {
        return question_impl.getAllData(currentPage, pageSize);
    }


}
